<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AfterSalesItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'request_id',
        'order_item_id',
        'quantity',
        'refund_amount',
        'admin_comment',
        'original_price',
        'calculation_note',
        'calculated_at',
    ];

    protected $casts = [
        'refund_amount' => 'decimal:2',
        'original_price' => 'decimal:2',
        'calculated_at' => 'datetime',
    ];

    /**
     * 关联售后申请
     */
    public function request(): BelongsTo
    {
        return $this->belongsTo(AfterSalesRequest::class, 'request_id');
    }

    /**
     * 关联订单项
     */
    public function orderItem(): BelongsTo
    {
        return $this->belongsTo(OrderItem::class);
    }
}
